//
//  MyViewController.m
//  weibo
//
//  Created by dllo on 16/6/13.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "MyViewController.h"
#import "MyModel.h"
#import "MyTableViewCell.h"

// 屏幕高
#define HEIGHT self.view.frame.size.height
// 屏幕宽
#define WIDTH self.view.frame.size.width


static NSString *const mineReuse = @"mineReuse";


@interface MyViewController ()
@property (nonatomic, strong) UITableView *myTabelView;
@property (nonatomic, strong) UIImageView *backImageV;
@property (nonatomic, copy) NSString *userName;
@property (nonatomic, copy) NSString *userPic;


@end

@implementation MyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor whiteColor];
//    self.navigationController.navigationBarHidden = YES;
    [self getData];
    
    self.myTabelView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    self.myTabelView.backgroundColor = [UIColor whiteColor];
    self.myTabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.myTabelView];
    
    //成为代理人
    self.myTabelView.delegate = self;
    self.myTabelView.dataSource = self;
    
    //注册
    UINib *nib = [UINib nibWithNibName:@"MyTableViewCell" bundle:[NSBundle mainBundle]];
    [self.myTabelView registerNib:nib forCellReuseIdentifier:mineReuse];
    
    //添加头视图
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 60, WIDTH, 185)];
    headerView.backgroundColor = [UIColor whiteColor];
    self.myTabelView.tableHeaderView = headerView;
    [self addHeader];
    

    
    
//    //添加夜间模式按钮
//    UIButton *naight = [UIButton buttonWithType:UIButtonTypeCustom];
//    [naight setImage:[UIImage imageNamed:@"btn_sun32"] forState:UIControlStateNormal];
//    naight.frame = CGRectMake(25, 25, 30, 30);
//    [self.myTabelView addSubview:naight];
//    [naight addTarget:self action:@selector(buttonAtcion:) forControlEvents:UIControlEventTouchUpInside];
    

    
    // Do any additional setup after loading the view.
}

//数据
- (void)getData
{
    self.myArrayM = [NSMutableArray array];
    self.myArrayMA = [NSMutableArray array];
    self.myArrayMB = [NSMutableArray array];
    self.myArrayMC = [NSMutableArray array];
    self.myArrayMD = [NSMutableArray array];
    self.myArrayME = [NSMutableArray array];
    self.myArrayMF = [NSMutableArray array];
    
    NSMutableArray *array = [NSMutableArray arrayWithObjects:@"新的好友", @"微博等级", @"我的相册",@"我的点评", @"我的赞", @"微博支付",@"微博运动", @"粉丝头条", @"粉丝服务", @"草稿箱",@"更多", nil];
    for (int i = 0; i < 11; i++) {
        MyModel *model = [[MyModel alloc] init];
        model.title = [array objectAtIndex:i];
        model.photo = [NSString  stringWithFormat:@"btn_mine_icon%d",i+1];
        if (i < 2) {
            [self.myArrayMA addObject:model];
        }else if (i >= 2 && i < 5) {
            [self.myArrayMB addObject:model];
        }else if (i >= 5 && i < 7) {
            [self.myArrayMC addObject:model];
        }else if (i >= 7 && i < 9) {
            [self.myArrayMD addObject:model];
        }else if (i == 9) {
            [self.myArrayME addObject:model];
        }else {
            [self.myArrayMF addObject:model];
        }
    }
    [self.myArrayM addObject:self.myArrayMA];
    [self.myArrayM addObject:self.myArrayMB];
    [self.myArrayM addObject:self.myArrayMC];
    [self.myArrayM addObject:self.myArrayMD];
    [self.myArrayM addObject:self.myArrayME];
    [self.myArrayM addObject:self.myArrayMF];
    //    NSLog(@"%@", self.myArrayM);
}


//addHearder
- (void)addHeader
{

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 10)];
    view.backgroundColor = [UIColor colorWithRed:245 / 255.0 green:245 / 255.0 blue:245 / 255.0 alpha:1.0];
    [self.myTabelView addSubview:view];
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 1)];
    view2.backgroundColor = [UIColor colorWithRed:225 / 255.0 green:225 / 255.0 blue:225 / 255.0 alpha:1.0];
    [self.myTabelView addSubview:view2];
    
    //白色透明条
    UIView *backV = [[UIView alloc] initWithFrame:CGRectMake(0, 115, WIDTH, 70)];
    backV.backgroundColor = [UIColor clearColor];
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 115, WIDTH, 70)];
    toolbar.barStyle = UIBarStyleBlackTranslucent;
    toolbar.alpha = 0.3;
    [self.myTabelView addSubview:toolbar];
    
    //loginButton
//    [self addHeaderLoginButton];
    
    //添加按钮
    [self addButton:@"微博" Number:1];
    [self addButton:@"关注" Number:2];
    [self addButton:@"粉丝" Number:3];
}

-(void)addButton:(NSString *)labelName Number:(NSInteger )number {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0 + WIDTH / 3 * (number - 1), 115, WIDTH / 3, 25)];
    label.backgroundColor = [UIColor clearColor];
    label.text = labelName;
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:14];
    label.textColor = [UIColor whiteColor];
    [self.myTabelView addSubview:label];
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = [UIColor clearColor];
    button.frame = CGRectMake(0 +  WIDTH / 3 * (number - 1), 115, WIDTH / 3 , 110);
    button.tag = 300000 + number;
    [button addTarget:self action:@selector(buttonAc) forControlEvents:UIControlEventTouchUpInside];
}

- (void)buttonAc
{
    
}

//分区的个数
-(NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.myArrayM.count;
}

//分区头高度
-(CGFloat )tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section
{
    return 10;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    //背景颜色
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor colorWithRed:235 / 255.0 green:235 / 255.0 blue:235 / 255.0 alpha:1.0];
    
    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 1)];
    view2.backgroundColor = [UIColor colorWithRed:225 / 255.0 green:225 / 255.0 blue:225 / 255.0 alpha:1.0];
    [self.myTabelView addSubview:view2];
    
    return view;
    
}

//cell高
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

//cell数
- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return self.myArrayMA.count;
    }
    if (section == 1) {
        return  self.myArrayMB.count;
    }
    if (section == 2) {
        return  self.myArrayMC.count;
    }
    if (section == 3) {
        return  self.myArrayMD.count;
    }
    if (section == 4) {
        return  self.myArrayME.count;
    }
    return self.myArrayMF.count;
}

//建cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:mineReuse];
    if (indexPath.section == 0) {
        MyModel *model = [self.myArrayMA objectAtIndex:indexPath.row];
        cell.myModel = model;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    if (indexPath.section == 1) {
        MyModel *model = [self.myArrayMB objectAtIndex:indexPath.row];
        cell.myModel = model;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    if (indexPath.section == 2) {
        MyModel *model = [self.myArrayMC objectAtIndex:indexPath.row];
        cell.myModel = model;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    if (indexPath.section == 3) {
        MyModel *model = [self.myArrayMD objectAtIndex:indexPath.row];
        cell.myModel = model;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    if (indexPath.section == 4) {
        MyModel *model = [self.myArrayME objectAtIndex:indexPath.row];
        cell.myModel = model;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    MyModel *model = [self.myArrayMF objectAtIndex:indexPath.row];
    cell.myModel = model;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
